package com.hdl.servlet.mallproduct;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.hdl.entity.MallProduct;
import com.hdl.service.MallProductService;
import com.hdl.service.impl.MallProductServiceImpl;

@WebServlet("/malltype.let")
public class MallTypeServlet extends HttpServlet{
	
   private MallProductService ms = new MallProductServiceImpl();
   @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
          //获取商品类型id
	      int typeid=Integer.valueOf(req.getParameter("typeid"));
	      
	      System.out.println(typeid);
	      
	      List<MallProduct> list = ms.SelectAllProductByTypeId(typeid);
	       //获取ObjectMapper对象
	 		ObjectMapper mapper = new ObjectMapper();
	 		
//	 		System.out.println(mapper.writeValueAsString(list));
	 		
	 		//设置相应头
	 		resp.setContentType("application/json;charset=utf-8");
	 		
	 		//写回数据
	 		mapper.writeValue(resp.getOutputStream(), list);
	 		
	 		
   }
   @Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}
